//
//  CAShapeLayer+ViewMask.m
//  CAShapeLayer
//
//  Created by 谢英泽 on 2016/10/21.
//  Copyright © 2016年 谢英泽. All rights reserved.
//

#import "CAShapeLayer+ViewMask.h"
#import <UIKit/UIKit.h>

@implementation CAShapeLayer (ViewMask)

+ (instancetype)createMaskLayerWithView:(UIView *)view
{
    //下面为调用方法
    //CAShapeLayer *shapeLayer = [CAShapeLayer createMaskLayerWithView:maskImgView];
    //maskImgView.layer.mask = shapeLayer;
    
    CGFloat width = CGRectGetWidth(view.frame);
    CGFloat height = CGRectGetHeight(view.frame);
    
    CGFloat rightSpace = 10;
    CGFloat topSpace   = 15;
    CGPoint point1 = CGPointMake(0, 0);
    CGPoint point2 = CGPointMake(width - rightSpace, 0);
    CGPoint point3 = CGPointMake(width - rightSpace, topSpace);
    CGPoint point4 = CGPointMake(width, topSpace+10);
    CGPoint point5 = CGPointMake(width - rightSpace, topSpace+20);
    CGPoint point6 = CGPointMake(width - rightSpace, height);
    CGPoint point7 = CGPointMake(0, height);
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:point1];
    [path addLineToPoint:point1];
    [path addLineToPoint:point2];
    [path addLineToPoint:point3];
    [path addLineToPoint:point4];
    [path addLineToPoint:point5];
    [path addLineToPoint:point6];
    [path addLineToPoint:point7];
    [path closePath];
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.path = path.CGPath;
    
    return layer;
}

+ (instancetype)createBottomMaskLayerWithView:(UIView *)view
{
    //下面为调用方法
    //CAShapeLayer *shapeLayer = [CAShapeLayer createMaskLayerWithView:maskImgView];
    //maskImgView.layer.mask = shapeLayer;
    
    CGFloat width = CGRectGetWidth(view.frame);
    CGFloat height = CGRectGetHeight(view.frame);
    
    CGFloat angleW = 4.f;
    CGFloat angeleH = 3.f;
    
    CGPoint point1 = CGPointMake(0, 0);
    CGPoint point2 = CGPointMake(0, height - angeleH);
    CGPoint point3 = CGPointMake((width - angleW)/2.f, height - angeleH);
    CGPoint point4 = CGPointMake(width/2.f, height);
    CGPoint point5 = CGPointMake((width + angleW)/2.f, height - angeleH);
    CGPoint point6 = CGPointMake(width, height - angeleH);
    CGPoint point7 = CGPointMake(width, 0);
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:point1];
    [path addLineToPoint:point1];
    [path addLineToPoint:point2];
    [path addLineToPoint:point3];
    [path addLineToPoint:point4];
    [path addLineToPoint:point5];
    [path addLineToPoint:point6];
    [path addLineToPoint:point7];
    [path closePath];
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.path = path.CGPath;
    
    return layer;
}



@end
